package com.lsa.letcode.the105.btZigzagTrav;

import java.io.IOException;
import java.util.Arrays;
import java.util.List;

import org.junit.Assert;
import org.junit.Test;

import com.lsa.letcode.common.LetCodeTestBase;
import com.lsa.letcode.common.TreeNode;
import com.lsa.letcode.common.TreeUtils;

public class BstLevelOrderZigzagTravTest extends LetCodeTestBase{
	@Test
	public void test() throws Exception {
		test(Arrays.asList(Arrays.asList(1), Arrays.asList(3,2), Arrays.asList(4,5,6,7), Arrays.asList(15,14,9,8)),
				"tree1.tgf");
		test(Arrays.asList(Arrays.asList(1), Arrays.asList(3,2), Arrays.asList(4,5,6,7)),
				"tree2.tgf");
		test(Arrays.asList(Arrays.asList(1), Arrays.asList(3,2), Arrays.asList(4,7), Arrays.asList(15,14,9,8)),
				"tree3.tgf");
		test(Arrays.asList(Arrays.asList(1)),
				"oneNode.tgf");
		test(Arrays.asList(Arrays.asList(1), Arrays.asList(3,2), Arrays.asList(4,5,6,7), Arrays.asList(15,14,13,12,11,10,9,8)),
				"full15.tgf");
	}

	private void test(List<List<Integer>> expected, String resName)
			throws IOException {
		TreeNode n = TreeUtils.fromTgf(this.getClass(), resName);
//		System.out.println(BinaryTreeUtils.toString(TreeUtils.copyAdaptTree(n)));
		Solution s = new Solution();
		List<List<Integer>> actual = s.zigzagLevelOrder(n);
//		System.out.println(actual);
		Assert.assertEquals(expected, actual);
	}
}
